home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.02 Feb 91 / Menu Bar Sources / HideMenuBarExample.p < prev    next >
Encoding:
Text File  |  1989-10-17  |  14.8 KB  |  808 lines  |  [TEXT/MPS ]

  1. {
  2. HideMenuBarExample.p
  3. MPW 3.0 Pascal source for menu bar hiding example.
  4. Copyright © 1989 D. Grant Leeper.
  5. All rights reserved.
  6. Publication rights granted to MacTutor.
  7. }
  8.  
  9. PROGRAM HideMenuBarExample;
  10.  
  11. USES
  12.     Types, Resources, QuickDraw, Fonts, Events,
  13.     Controls, Windows, Menus, TextEdit, Dialogs,
  14.     ToolUtils, OSUtils, SegLoad, Files, Packages,
  15.     Desk, DiskInit, Memory, OSEvents,
  16.     Traps, ShowHideMBar;
  17.  
  18. CONST
  19.     kSysEnvironsVersion =    1;
  20.     
  21.     kMinHeap =            7 * 1024;
  22.     kMinSpace =            2 * 1024;
  23.     
  24.     kMinDocH =            424;
  25.     kMinDocV =            70;
  26.     
  27.     kScrollBarAdjust =    15;
  28.     
  29.     kExtremeNeg =        -32768;
  30.     kExtremePos =        32767 - 1;
  31.  
  32.     rWindow =            128;
  33.     rMenuBar =            128;
  34.     rAboutAlert =        128;
  35.     rFatalAlert =        129;
  36.     
  37.     rMessages =            128;
  38.     iSelectApp =        1;
  39.     iSelectWind =        2;
  40.     iAltSelectWind =    3;
  41.     iCommandSpace =        4;
  42.     iAltCommandSpace =    5;
  43.     iClick =            6;
  44.     iCommandClick =        7;
  45.     
  46.     mApple =            128;
  47.     iAbout =            1;
  48.     
  49.     mFile =                129;
  50.     iClose =            1;
  51.     iQuit =                2;
  52.     
  53.     mEdit =                130;
  54.     iUndo =                1;
  55.     iCut =                3;
  56.     iCopy =                4;
  57.     iPaste =            5;
  58.     iClear =            6;
  59.     
  60. VAR
  61.     gMac:                SysEnvRec;
  62.     gHasWaitNextEvent:    BOOLEAN;
  63.     gInBackground:        BOOLEAN;
  64.     { This keeps track of when we need to
  65.       adjust the menus }
  66.     gDirtyMenus:        BOOLEAN;
  67.     { gHasMenuBar saves the visibility of the
  68.       menu bar while we're in the background. }
  69.     gHasMenuBar:        BOOLEAN;
  70.     { Create these once rather than each time
  71.       through the event loop. }
  72.     gOutsideRgn:        RgnHandle;
  73.     gInsideRgn:            RgnHandle;
  74.  
  75. {$S Main}
  76. FUNCTION  IsDAWindow(window: WindowPtr): BOOLEAN;
  77.  
  78.     BEGIN
  79.     IsDAWindow :=
  80.         (window <> NIL) &
  81.         (WindowPeek(window)^.windowKind < 0)
  82.     END; { IsDAWindow }
  83.  
  84. {$S Main}
  85. FUNCTION  IsAppWindow(window: WindowPtr): BOOLEAN;
  86.  
  87.     BEGIN
  88.     IsAppWindow :=
  89.         (window <> NIL) &
  90.         (WindowPeek(window)^.windowKind =
  91.          userKind)
  92.     END; { IsAppWindow }
  93.  
  94. {$S Main}
  95. PROCEDURE DoToAllAppWindows(
  96.             PROCEDURE DoThis(window: WindowPtr));
  97.  
  98.     VAR
  99.         window:    WindowPeek;
  100.     
  101.     BEGIN
  102.     window := WindowPeek(FrontWindow);
  103.     WHILE window <> NIL DO
  104.         BEGIN
  105.         IF window^.windowKind = userKind THEN
  106.             DoThis(WindowPtr(window));
  107.         window := window^.nextWindow
  108.         END { WHILE }
  109.     END; { DoToAllAppWindows }
  110.  
  111. {$S Main}
  112. PROCEDURE FatalError;
  113.  
  114.     VAR
  115.         itemHit:    INTEGER;
  116.     
  117.     BEGIN
  118.     SetCursor(arrow);
  119.     itemHit := CautionAlert(rFatalAlert, NIL);
  120.     { Be sure the menu bar is visible at exit
  121.       time, but check first for the 128K ROM
  122.       since we may have been called because
  123.       it's not available. }
  124.     IF gMac.machineType >= 0 THEN
  125.         ShowMenuBar;
  126.     ExitToShell
  127.     END; { FatalError }
  128.  
  129. {$S Main}
  130. FUNCTION  DoCloseWindow(window: WindowPtr): BOOLEAN;
  131.  
  132.     BEGIN
  133.     DoCloseWindow := TRUE;
  134.     IF IsAppWindow(window) THEN
  135.         BEGIN
  136.         CloseWindow(window);
  137.         DisposPtr(Ptr(window))
  138.         END { IF }
  139.     ELSE IF IsDAWindow(window) THEN
  140.         CloseDeskAcc(WindowPeek(window)^.windowKind)
  141.     END; { DoCloseWindow }
  142.  
  143. {$S Initialize}
  144. PROCEDURE BringAppToFront;
  145.  
  146.     VAR
  147.         count:    INTEGER;
  148.         event:    EventRecord;
  149.     
  150.     BEGIN
  151.     FOR count := 1 TO 3 DO
  152.         IF EventAvail(everyEvent, event) THEN
  153.             ; { Ignore it }
  154.     END; { BringAppToFront }
  155.  
  156. {$S Initialize}
  157. PROCEDURE Initialize;
  158.  
  159.     VAR
  160.         bIgnore:    BOOLEAN;
  161.         event:        EventRecord;
  162.         ignore:        OSErr;
  163.         total:        LONGINT;
  164.         contig:        LONGINT;
  165.         storage:    Ptr;
  166.         window:        WindowPtr;
  167.         menuBar:    Handle;
  168.     
  169.     BEGIN
  170.     InitGraf(@thePort);
  171.     InitFonts;
  172.     InitWindows;
  173.     InitMenus;
  174.     TEInit;
  175.     InitDialogs(NIL);
  176.     InitCursor;
  177.     
  178.     BringAppToFront;
  179.     
  180.     { SysEnvirons must be called before calling
  181.       FatalError. }
  182.     ignore := SysEnvirons(kSysEnvironsVersion,
  183.                           gMac);
  184.     
  185.     { Need 128K ROMS to change menu bar height. }
  186.     IF gMac.machineType < 0 THEN
  187.         FatalError;
  188.     
  189.     { The menu bar can be hidden now if desired. }
  190.     HideMenuBar;
  191.     
  192.     IF ORD(GetApplLimit) - ORD(ApplicZone) <
  193.        kMinHeap THEN
  194.         FatalError;
  195.     
  196.     PurgeSpace(total, contig);
  197.     IF total < kMinSpace THEN
  198.         FatalError;
  199.     
  200.     gHasWaitNextEvent :=
  201.         GetTrapAddress(_Unimplemented) <>
  202.         NGetTrapAddress(_WaitNextEvent, ToolTrap);
  203.     
  204.     gInBackground := FALSE;
  205.     
  206.     storage := NewPtr(SizeOf(WindowRecord));
  207.     IF storage = NIL THEN
  208.         FatalError;
  209.     IF gMac.hasColorQD THEN
  210.         window := GetNewCWindow(rWindow, storage,
  211.                                 Pointer(-1))
  212.     ELSE
  213.         window := GetNewWindow(rWindow, storage,
  214.                                Pointer(-1));
  215.     IF window = NIL THEN
  216.         FatalError;
  217.         
  218.     menuBar := GetNewMBar(rMenuBar);
  219.     IF menuBar = NIL THEN
  220.         FatalError;
  221.     SetMenuBar(menuBar);
  222.     DisposHandle(menuBar);
  223.     AddResMenu(GetMHandle(mApple), 'DRVR');
  224.     DrawMenuBar;
  225.     gDirtyMenus := TRUE;
  226.     
  227.     gOutsideRgn := NewRgn;
  228.     gInsideRgn := NewRgn
  229.     END; { Initialize }
  230.  
  231. {$S Main}
  232. PROCEDURE Terminate;
  233.  
  234.     VAR
  235.         window:    WindowPtr;
  236.  
  237.     BEGIN
  238.     window := FrontWindow;
  239.     WHILE window <> NIL DO
  240.         IF DoCloseWindow(window) THEN
  241.             window := FrontWindow
  242.         ELSE
  243.             Exit(Terminate);
  244.     { Must restore menu bar
  245.       before quitting }
  246.     ShowMenuBar;
  247.     ExitToShell
  248.     END; { Terminate }
  249.  
  250. {$S Main}
  251. PROCEDURE AdjustMenus;
  252.  
  253.     VAR
  254.         window:        WindowPtr;
  255.         appWind:    BOOLEAN;
  256.         daWind:        BOOLEAN;
  257.         redraw:        BOOLEAN;
  258.         menu:        MenuHandle;
  259.         wasEnabled:    BOOLEAN;
  260.     
  261.     BEGIN
  262.     window := FrontWindow;
  263.     appWind := IsAppWindow(window);
  264.     daWind := IsDAWindow(window);
  265.     redraw := FALSE;
  266.     
  267.     menu := GetMHandle(mFile);
  268.     IF daWind THEN
  269.         EnableItem(menu, iClose)
  270.     ELSE
  271.         DisableItem(menu, iClose);
  272.     
  273.     menu := GetMHandle(mEdit);
  274.     wasEnabled := Odd(menu^^.enableFlags);
  275.     IF daWind THEN
  276.         BEGIN
  277.         EnableItem(menu, 0);
  278.         EnableItem(menu, iUndo);
  279.         EnableItem(menu, iCut);
  280.         EnableItem(menu, iCopy);
  281.         EnableItem(menu, iPaste);
  282.         EnableItem(menu, iClear)
  283.         END { IF }
  284.     ELSE
  285.         BEGIN
  286.         DisableItem(menu, 0);
  287.         DisableItem(menu, iUndo);
  288.         DisableItem(menu, iCut);
  289.         DisableItem(menu, iCopy);
  290.         DisableItem(menu, iClear);
  291.         DisableItem(menu, iPaste)
  292.         END; { ELSE }
  293.     IF Odd(menu^^.enableFlags) <> wasEnabled THEN
  294.         redraw := TRUE;
  295.     
  296.     IF redraw THEN
  297.         DrawMenuBar
  298.     END; { AdjustMenus }
  299.  
  300. {$S Main}
  301. PROCEDURE DoMenuCommand(menuResult: LONGINT);
  302.  
  303.     VAR
  304.         menu:        INTEGER;
  305.         item:        INTEGER;
  306.         ignore:        INTEGER;
  307.         name:        Str255;
  308.         window:        WindowPtr;
  309.         bIgnore:    BOOLEAN;
  310.     
  311.     BEGIN
  312.     menu := HiWrd(menuResult);
  313.     item := LoWrd(menuResult);
  314.     CASE menu OF
  315.         
  316.         mApple:
  317.             CASE item OF
  318.                 
  319.                 iAbout:
  320.                     ignore := Alert(rAboutAlert,
  321.                                     NIL);
  322.                 
  323.                 OTHERWISE
  324.                     BEGIN
  325.                     GetItem(GetMHandle(mApple),
  326.                             item, name);
  327.                     ignore := OpenDeskAcc(name);
  328.                     gDirtyMenus := TRUE
  329.                     END { OTHERWISE }
  330.                 
  331.                 END; { CASE }
  332.         
  333.         mFile:
  334.             CASE item OF
  335.                 
  336.                 iClose:
  337.                     BEGIN
  338.                     window := FrontWindow;
  339.                     IF IsDAWindow(window) THEN
  340.                         CloseDeskAcc(
  341.                             WindowPeek(window)^.
  342.                                 windowKind);
  343.                     gDirtyMenus := TRUE
  344.                     END; { iClose }
  345.                 
  346.                 iQuit:
  347.                     Terminate
  348.                 
  349.                 END; { CASE }
  350.         
  351.         mEdit:
  352.             bIgnore := SystemEdit(item - 1)
  353.         
  354.         END; { CASE }
  355.     
  356.     HiliteMenu(0)
  357.     END; { DoMenuCommand }
  358.  
  359. {$S Main}
  360. PROCEDURE DrawWindow(window: WindowPtr);
  361.  
  362.     VAR
  363.         str:    Str255;
  364.     
  365.     BEGIN
  366.     SetPort(window);
  367.     EraseRect(window^.portRect);
  368.     DrawGrowIcon(window);
  369.     
  370.     { We display different messages here
  371.       depending on our foreground/background
  372.       and activate/inactivate states. }
  373.     
  374.     IF gInBackground THEN
  375.         BEGIN
  376.         GetIndString(str, rMessages,
  377.                      iSelectApp);
  378.         MoveTo(10, 32);
  379.         DrawString(str)
  380.         END { IF }
  381.     
  382.     ELSE IF window <> FrontWindow THEN
  383.         BEGIN
  384.         IF MenuBarVisible THEN
  385.             GetIndString(str, rMessages,
  386.                          iSelectWind)
  387.         ELSE
  388.             GetIndString(str, rMessages,
  389.                          iAltSelectWind);
  390.         MoveTo(10, 32);
  391.         DrawString(str)
  392.         END { ELSE IF }
  393.     
  394.     ELSE
  395.         IF MenuBarVisible THEN
  396.             BEGIN
  397.             MoveTo(10, 32);
  398.             GetIndString(str, rMessages,
  399.                          iCommandSpace);
  400.             DrawString(str)
  401.             END { IF }
  402.         ELSE
  403.             BEGIN
  404.             MoveTo(10, 16);
  405.             GetIndString(str, rMessages,
  406.                          iAltCommandSpace);
  407.             DrawString(str);
  408.             MoveTo(10, 32);
  409.             GetIndString(str, rMessages,
  410.                          iClick);
  411.             DrawString(str);
  412.             MoveTo(10, 48);
  413.             GetIndString(str, rMessages,
  414.                          iCommandClick);
  415.             DrawString(str)
  416.             END { ELSE }
  417.     END; { DrawWindow }
  418.  
  419. {$S Main}
  420. PROCEDURE InvalContentRgn(window: WindowPtr);
  421.  
  422.     VAR
  423.         r:    Rect;
  424.     
  425.     BEGIN
  426.     SetPort(window);
  427.     r := window^.portRect;
  428.     r.bottom := r.bottom - kScrollBarAdjust;
  429.     r.right := r.right - kScrollBarAdjust;
  430.     InvalRect(r)
  431.     END; { InvalContentRgn }
  432.  
  433. {$S Main}
  434. PROCEDURE InvalAppWindContents;
  435. { Since our window may be behind some DA windows
  436.   we must check all the windows in our layer. }
  437.  
  438.     BEGIN
  439.     DoToAllAppWindows(InvalContentRgn)
  440.     END; { InvalAppWindContents }
  441.  
  442. {$S Main}
  443. PROCEDURE InvalGrowRgn(window: WindowPtr);
  444.  
  445.     VAR
  446.         r:    Rect;
  447.     
  448.     BEGIN
  449.     SetPort(window);
  450.     r := window^.portRect;
  451.     r.top := r.bottom - kScrollBarAdjust;
  452.     InvalRect(r);
  453.     r := window^.portRect;
  454.     r.left := r.right - kScrollBarAdjust;
  455.     InvalRect(r)
  456.     END; { InvalGrowRgn }
  457.  
  458. {$S Main}
  459. PROCEDURE DoGrowWindow(window: WindowPtr;
  460.                        event: EventRecord);
  461.  
  462.     VAR
  463.         tempRect:        Rect;
  464.         growResult:        LONGINT;
  465.     
  466.     BEGIN
  467.     WITH screenBits.bounds DO
  468.         SetRect(tempRect, kMinDocH, kMinDocV,
  469.                 right, bottom);
  470.     growResult := GrowWindow(window, event.where,
  471.                              tempRect);
  472.     IF growResult <> 0 THEN
  473.         BEGIN
  474.         InvalGrowRgn(window);
  475.         SizeWindow(window, LoWrd(growResult),
  476.                    HiWrd(growResult), TRUE);
  477.         InvalGrowRgn(window)
  478.         END { IF }
  479.     END; { DoGrowWindow }
  480.  
  481. {$S Main}
  482. PROCEDURE DoZoomWindow(window: WindowPtr;
  483.                        part: INTEGER);
  484.  
  485.     BEGIN
  486.     SetPort(window);
  487.     EraseRect(window^.portRect);
  488.     ZoomWindow(window, part, FALSE)
  489.     END; { DoZoomWindow }
  490.  
  491. {$S Main}
  492. PROCEDURE DoUpdate(window: WindowPtr);
  493.  
  494.     BEGIN
  495.     IF IsAppWindow(window) THEN
  496.         BEGIN
  497.         BeginUpdate(window);
  498.         IF NOT EmptyRgn(window^.visRgn) THEN
  499.             DrawWindow(window);
  500.         EndUpdate(window)
  501.         END { IF }
  502.     END; { DoUpdate }
  503.  
  504. {$S Main}
  505. PROCEDURE DoActivate(window: WindowPtr;
  506.                      becomingActive: BOOLEAN);
  507.  
  508.     BEGIN
  509.     IF IsAppWindow(window) THEN
  510.         BEGIN
  511.         { Message to user changes when
  512.           activated or deactivated. }
  513.         InvalContentRgn(window);
  514.         DrawGrowIcon(window);
  515.         gDirtyMenus := TRUE
  516.         END { IF }
  517.     END; { DoActivate }
  518.  
  519. {$S Main}
  520. PROCEDURE DoDisk(message: LONGINT);
  521.  
  522.     CONST
  523.         kDILeft =    70;
  524.         kDITop =    50;
  525.     
  526.     VAR
  527.         where:    Point;
  528.     
  529.     BEGIN
  530.     IF HiWrd(message) <> noErr THEN
  531.         BEGIN
  532.         SetPt(where, kDILeft, kDITop);
  533.         IF DIBadMount(where, message) = 0 THEN
  534.             { Ignore it }
  535.         END { IF }
  536.     END; { DoDisk }
  537.  
  538. {$S Main}
  539. PROCEDURE DoSuspendResume(suspend: BOOLEAN);
  540.  
  541.     BEGIN
  542.     gInBackground := suspend;
  543.     
  544.     IF suspend THEN
  545.     { Save menu bars visibility for when we resume
  546.       then force the menu bar to be displayed. }
  547.         BEGIN
  548.         gHasMenuBar := MenuBarVisible;
  549.         ShowMenuBar
  550.         END { IF }
  551.     
  552.     ELSE IF NOT gHasMenuBar THEN
  553.     { Resuming, hide the menu bar if it was
  554.       hidden prior to our suspension. }
  555.         HideMenuBar;
  556.     
  557.     DoActivate(FrontWindow, NOT suspend);
  558.     
  559.     { Change message to user when
  560.       suspended or resumed. }
  561.     InvalAppWindContents
  562.     END; { DoSuspendResume }
  563.  
  564. {$S Main}
  565. PROCEDURE AdjustCursor(mouse: Point;
  566.                        cursorRgn: RgnHandle);
  567.  
  568.     VAR
  569.         window:        WindowPtr;
  570.         insideRect:    Rect;
  571.     
  572.     BEGIN
  573.     window := FrontWindow;
  574.     IF NOT gInBackground &
  575.        NOT IsDAWindow(window) THEN
  576.         BEGIN
  577.         SetRectRgn(gOutsideRgn,
  578.                    kExtremeNeg, kExtremeNeg,
  579.                    kExtremePos, kExtremePos);
  580.         
  581.         IF IsAppWindow(window) THEN
  582.             BEGIN
  583.             insideRect := window^.portRect;
  584.             insideRect.bottom :=
  585.                 insideRect.bottom -
  586.                 kScrollBarAdjust;
  587.             insideRect.right :=
  588.                 insideRect.right -
  589.                 kScrollBarAdjust;
  590.             SetPort(window);
  591.             LocalToGlobal(insideRect.topLeft);
  592.             LocalToGlobal(insideRect.botRight);
  593.             RectRgn(gInsideRgn, insideRect)
  594.             END; { IF }
  595.         
  596.         DiffRgn(gOutsideRgn, gInsideRgn,
  597.                 gOutsideRgn);
  598.         
  599.         IF PtInRgn(mouse, gInsideRgn) THEN
  600.             BEGIN
  601.             SetCursor(GetCursor(plusCursor)^^);
  602.             CopyRgn(gInsideRgn, cursorRgn)
  603.             END { IF }
  604.         ELSE
  605.             BEGIN
  606.             SetCursor(arrow);
  607.             CopyRgn(gOutsideRgn, cursorRgn)
  608.             END; { ELSE }
  609.         
  610.         SetEmptyRgn(gOutsideRgn);
  611.         SetEmptyRgn(gInsideRgn)
  612.         END { IF }
  613.     END; { AdjustCursor }
  614.  
  615. {$S Main}
  616. PROCEDURE DoEvent(event: EventRecord);
  617.  
  618.     CONST
  619.         kOSEvent =                app4Evt;
  620.         kSuspendResumeMessage =    1;
  621.         kResumeMask =            1;
  622.     
  623.     VAR
  624.         part:    INTEGER;
  625.         window:    WindowPtr;
  626.         key:    CHAR;
  627.     
  628.     BEGIN
  629.     CASE event.what OF
  630.         
  631.         mouseDown:
  632.             BEGIN
  633.             part := FindWindow(event.where,
  634.                                window);
  635.             
  636.             CASE part OF
  637.                 
  638.                 inDesk:
  639.                     IF PtInMenuBar(
  640.                             event.where) THEN
  641.                         { User clicked in hidden
  642.                           menu bar.  Lets show
  643.                           off some tricks. }
  644.                         BEGIN
  645.                         { Show menu bar first if
  646.                           command key pressed,
  647.                           else just show menus
  648.                           without the bar. }
  649.                         IF BAnd(event.modifiers,
  650.                                 cmdKey) <> 0 THEN
  651.                             ShowMenuBar;
  652.                         DoMenuCommand(
  653.                             HiddenMenuSelect(
  654.                                 event.where));
  655.                         { If we showed the menu
  656.                           bar here we must be
  657.                           sure HiliteMenu(0) is
  658.                           called before we hide
  659.                           it again. In our case
  660.                           DoMenuCommand calls it
  661.                           for us. }
  662.                         IF BAnd(event.modifiers,
  663.                                 cmdKey) <> 0 THEN
  664.                             HideMenuBar
  665.                         END; { IF }
  666.                 
  667.                 inMenuBar:
  668.                     DoMenuCommand(
  669.                         MenuSelect(event.where));
  670.                 
  671.                 inSysWindow:
  672.                     SystemClick(event, window);
  673.                 
  674.                 inContent:
  675.                     IF window <> FrontWindow THEN
  676.                         SelectWindow(window);
  677.                 
  678.                 inDrag:
  679.                     DragWindow(window,
  680.                                event.where,
  681.                                screenBits.bounds);
  682.                 
  683.                 inGrow:
  684.                     DoGrowWindow(window, event);
  685.                 
  686.                 inZoomIn, inZoomOut:
  687.                     IF TrackBox(window,
  688.                                 event.where,
  689.                                 part) THEN
  690.                         DoZoomWindow(window,
  691.                                      part)
  692.                 END { CASE }
  693.             END; { mouseDown }
  694.         
  695.         keyDown, autoKey:
  696.             BEGIN
  697.             key := Chr(BAnd(event.message,
  698.                             charCodeMask));
  699.             IF BAnd(event.modifiers,
  700.                     cmdKey) <> 0 THEN
  701.                 IF event.what = keyDown THEN
  702.                     IF key = ' ' THEN
  703.                         { User typed
  704.                           command-space so
  705.                           toggle the menu bar. }
  706.                         BEGIN
  707.                         IF MenuBarVisible THEN
  708.                             HideMenuBar
  709.                         ELSE
  710.                             ShowMenuBar;
  711.                         { Change message to user
  712.                           when menu is hidden
  713.                           or made visible. }
  714.                         InvalAppWindContents
  715.                         END { IF }
  716.                     ELSE
  717.                         DoMenuCommand(
  718.                             MenuKey(key))
  719.             END; { keyDown, autoKey }
  720.         
  721.         activateEvt:
  722.             DoActivate(WindowPtr(event.message),
  723.                        BAnd(event.modifiers,
  724.                             activeFlag) <> 0);
  725.         
  726.         updateEvt:
  727.             DoUpdate(WindowPtr(event.message));
  728.         
  729.         diskEvt:
  730.             DoDisk(event.message);
  731.         
  732.         kOSEvent:
  733.             CASE BAnd(BRotL(event.message, 8),
  734.                       $FF) OF
  735.                 
  736.                 kSuspendResumeMessage:
  737.                     DoSuspendResume(
  738.                         BAnd(event.message,
  739.                         kResumeMask) = 0)
  740.                 
  741.                 END { CASE }
  742.         END { CASE }
  743.     END; { DoEvent }
  744.  
  745. {$S Main}
  746. FUNCTION  GlobalMouse: Point;
  747.  
  748.     CONST
  749.         kNoEvents =    0;
  750.     
  751.     VAR
  752.         ignore:    BOOLEAN;
  753.         event:    EventRecord;
  754.     
  755.     BEGIN
  756.     ignore := OSEventAvail(kNoEvents, event);
  757.     GlobalMouse := event.where
  758.     END; { GlobalMouse }
  759.  
  760. {$S Main}
  761. PROCEDURE EventLoop;
  762.  
  763.     VAR
  764.         cursorRgn:    RgnHandle;
  765.         gotEvent:    BOOLEAN;
  766.         event:        EventRecord;
  767.     
  768.     BEGIN
  769.     cursorRgn := NewRgn;
  770.     WHILE TRUE DO
  771.         BEGIN
  772.         IF gDirtyMenus THEN
  773.             BEGIN
  774.             AdjustMenus;
  775.             gDirtyMenus := FALSE
  776.             END; { IF }
  777.         
  778.         AdjustCursor(GlobalMouse, cursorRgn);
  779.         
  780.         IF gHasWaitNextEvent THEN
  781.             gotEvent :=
  782.                 WaitNextEvent(everyEvent,
  783.                               event, 30,
  784.                               cursorRgn)
  785.         ELSE
  786.             BEGIN
  787.             SystemTask;
  788.             gotEvent := GetNextEvent(everyEvent,
  789.                                      event)
  790.             END; { ELSE }
  791.         
  792.         IF gotEvent THEN
  793.             AdjustCursor(event.where, cursorRgn);
  794.         
  795.         DoEvent(event)
  796.         END { WHILE }
  797.     END; { EventLoop }
  798.  
  799. PROCEDURE _DataInit; EXTERNAL;
  800.  
  801. BEGIN
  802. UnloadSeg(@_DataInit);
  803. MaxApplZone;
  804. Initialize;
  805. UnloadSeg(@Initialize);
  806. EventLoop
  807. END. { HideMenuBarExample }
  808.